/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package optinsa;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import javax.swing.JPanel;

/**
 *
 * @author falxa
 */
public class JobGraph extends JPanel
{
    public static final int TIMEWIDTH = 10;
    public static final int TASKHEIGHT = 10;
    public static final int GAPWIDTH = 5;
    public Color[] COLOURS = {  Color.GREEN, Color.BLUE, Color.MAGENTA, Color.BLACK, Color.YELLOW,
                                Color.RED, Color.BLACK, Color.CYAN,  Color.PINK, Color.WHITE, };
    
    private ArrayList<Job> jobs;
    
    public JobGraph(ArrayList<Job> jobs)
    {
        this.jobs = jobs;
    }
    
    public void paintComponent(Graphics g) 
    {
        Graphics2D g2 = (Graphics2D) g;
        Rectangle2D rect;
        
        Task t;
        int duration, date;
        int currentY = 0;
        int currentX, currentW;
        
        for (int i=0; i<this.jobs.size(); i++)
        {
            currentX = 0;
                    
            for (int j=0; j<this.jobs.get(i).getTasks().size(); j++)
            {
                t = this.jobs.get(i).getTasks().get(j);
                duration = t.getDuration();
                date = t.getDate();
                
                currentX = date*TIMEWIDTH;
                currentW = duration*TIMEWIDTH;
                
                Color c = COLOURS[t.getRessource().getID()];
                g2.setPaint(c);
                rect = new Rectangle2D.Double(currentX, currentY, currentW, TASKHEIGHT);
                g2.fill(rect);
            }
            
            currentY += TASKHEIGHT + GAPWIDTH;
        }
        
        currentX = 0;
        Line2D lin;
        g2.setPaint(Color.LIGHT_GRAY);
        while (currentX < Problem.WIDTH)
        {
            currentX += TIMEWIDTH;
            lin = new Line2D.Float(currentX, 0, currentX, Problem.HEIGHT);
            g2.draw(lin);
        }
        
        
    }
    
}
